//
//  SLApp.m
//  SLAdingo
//
//  Created by 徐 廷 on 10/04/01.
//  Copyright 2010 adingo Inc. All rights reserved.
//

#import "SLApp.h"


@implementation SLApp

+ (NSString *) getSystemFolder:(NSSearchPathDirectory) dir{
	NSArray *paths = NSSearchPathForDirectoriesInDomains(dir, NSUserDomainMask, YES);
	NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
    return basePath;
}

+ (NSString *) getDocumentFolder{
	return [SLApp getSystemFolder:NSDocumentDirectory];
}

+ (NSString *) getTempFolder{
	return NSTemporaryDirectory();
}

+ (NSString *) getLibraryFolder{
	return [SLApp getSystemFolder:NSLibraryDirectory];
}

+ (NSString *) getCacheFolder{
	return [SLApp getSystemFolder:NSCachesDirectory];
}

+ (NSString *) getDownloadFolder{
	return [SLApp getSystemFolder:NSDownloadsDirectory];
}

+ (NSString *) getBundleDirectory{
	return [[NSBundle mainBundle] resourcePath];
}

#pragma mark -
#pragma mark Center Location
+ (CLLocationCoordinate2D) getTokyoCenterLocation{
    CLLocationCoordinate2D tokyoCenterCoordinate;
    tokyoCenterCoordinate.latitude = 35.6838512;
    tokyoCenterCoordinate.longitude = 139.7539732;
    return tokyoCenterCoordinate;
}


#pragma mark -
#pragma mark Bitwise Options Operations
+ (BOOL) isOptionSet:(BooleanOptions)anOption inProperty:(UInt32)aProperty{
	return ((aProperty & anOption) == anOption);
}

+ (UInt32) setOption:(BooleanOptions)anOption onOff:(BOOL)onOrOff inProperty:(UInt32)aProperty{
	if (YES == onOrOff) {
		// Set the option on;
		if (![SLApp isOptionSet:anOption inProperty:aProperty]) {
			// 0|1 = 1, 1|0 = 1, 0|0 = 0, 1|1 = 1
			aProperty |= anOption;
		}
	}else {
		// Set the option off;
		if ([SLApp isOptionSet:anOption inProperty:aProperty]) {
			// 0^1 = 1, 1^0 = 1, 0^0 = 0, 1^1 = 0
			aProperty ^= anOption;
		}
	}
	return aProperty;
}


@end
